﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YetAnotherChat.ChatCore.Interfaces;
using YetAnotherChat.ChatCore.Models;

namespace YetAnotherChat.EntityFrameworkDataAccess.RepositoryImp
{
    public class MessageRepository: GenericRepositoryBase<ChatMessage>, IMessageRepository
    {
        public void SaveMessages(ChatMessage[] messages)
        {
            try
            {
                foreach (var m in messages)
                {
                    if (!m.IsCloned)
                    {
                        throw new ArgumentException("obj must be a cloned object");
                    }
                    _entitySet.Attach(m);
                    _context.Entry(m).State = System.Data.EntityState.Added;
                }
                
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                throw;
            }
        }
    }
}
